<?php

namespace app\model;

use think\Model;

class VideoCustom extends Model
{
	// 设置当前模型对应的数据表
	protected $name = 'video_custom';
	// 设置当前模型主键
	protected $pk = 'id';

	// 获取所有数据
	public function getAllData($where = [], $fields = '*', $order = 'id desc')
	{
		$data = self::where($where)->field($fields)->order($order)->select();
		return $data ? $data->toArray() : [];
	}

	public function getCustomById($id = [], $fields = '*')
	{
		return self::where(['id' => $id])->field($fields)->find();
	}

	/**
	 * 添加/编辑
	 *
	 * @dateTime 2022/09/19
	 * @author feikor
	 * @param array $params
	 * @return int
	 */
	public function edit(array $params)
	{
		if (empty($params['id'])) {
			$data = $this::create($params);
			return $data->id;
		}
		$this::update($params);
		return $params['id'];
	}
}